﻿using System.Xml;

namespace BuzzX8.Xmpp.StreamElements
{
    public class StreamFeature : StreamElement
    {
        public StreamFeature(string name, string featureNamespace) : this(name, featureNamespace, false)
        {
        }

        public StreamFeature(string name, string featureNamespace, bool required) : base(name, featureNamespace)
        {
            Required = required;
        }

        public bool Required { get; set; }

        protected override void WritePayload(XmlWriter writer)
        {
            if (Required) writer.WriteStartElement("required");
        }

        public override bool Equals(object obj)
        {
            if (!(obj is StreamFeature) && obj == null) return false;
            StreamFeature feature = (StreamFeature) obj;
            return feature.Name == Name && feature.Namespace.Equals(Namespace) && feature.Required == Required;
        }
    }
}
